<?php
//网站配置的添加
function msg($msg, $url=''){
		if($url == ''){
			$ad = "window.history.go(-1)";
		}else{
			$ad = "window.location.href='{$url}'";
		}
		exit("<script>alert('{$msg}');{$ad};</script>");
	}

	include_once("./com.php");
	$rem="select * from system";
	$ser=mysql_query($rem);
	if(isset($_GET['sub'])){
		 $ctitle=$_GET['ctitle'];
		 $cname=$_GET['cname'];
		 $cvalue=$_GET['cvalue'];

if (empty($ctitle)) {
		msg('配置项说明不能为空');
	}
	if (empty($cname)) {
		msg('变量名称不能为空');
	}
	/*	 if (empty($ctitle)) {
		 	echo"<script>
		alter('配置项说明不能为空')
		location.href='conf_add1.php'
		</script>";
	}
	if (empty($cname)) {
		 	echo"<script>
		alter('变量名称不能为空')
		location.href='conf_add1.php'
		</script>";
		
	}    */
$sel="select * from system where ctitle='$ctitle'";
	$ren=mysql_query($sel);
	if(mysql_num_rows($ren)>0){
		msg("配置项标题已存在","./conf_add1.php");
		exit;
}
$sel="select * from system where cname='$cname'";
	$ren=mysql_query($sel);
	if(mysql_num_rows($ren)>0){
		msg("配置项名已存在","./conf_add1.php");
		exit;
}



		 $ins="insert into system(ctitle,cname,cvalue)values('$ctitle','$cname','$cvalue')";
		mysql_query($ins);
		if(mysql_affected_rows()>0){
			echo"<script>
					alert('添加成功')
					location.href='conf_add.php'
					</script>";
		}else {
			echo"<script>
					alert('添加失败')
					location.href='conf_add1.php'
					</script>";
			
		}
	};
	


?>
	

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加网站配置</title>
<base target="_self">
<link rel="stylesheet" type="text/css" href="skin/css/base.css" />
<link rel="stylesheet" type="text/css" href="skin/css/main.css" />
</head>
<body leftmargin="8" topmargin='8'>
<table width="98%" align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#CBD8AC" style="margin-bottom:8px;margin-top:8px;">
  <tr>
    <td background="skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' colspan="2"><span><img src='skin/images/frame/arr3.gif' style='margin-right:10px;'>添加网站配置</span></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>
		<table style="margin-bottom:8px;margin-top:8px;margin-left:20px;">
			<form action="" method="" >
			 <tr>
				<td>配置项目标题： &nbsp;&nbsp;<input type="text" name="ctitle" value=""></td>	
			 </tr>
			 <tr>
				 <td>配置项名称： &nbsp;&nbsp;<input type="text" name="cname" value=""></td>
			</tr>
			 <tr>
				 <td>配置项值： &nbsp;&nbsp;<input type="text" name="cvalue" value=""></td>
			</tr>
			
			 <tr>
				 	<td colspan="2" align="center" height="40px">
				 	<input type="submit" name="sub" value=" 添加 " class="coolbt2"></td>
			 </tr>
			</form>
		</table>
	</td>
  </tr>
</table>
</body>
</html>